package com.pai4j.zwiki.dto;

import com.pai4j.zwiki.enums.UserVipLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * 用户VIP信息
 * 用于查询用户VIP等级和权益
 *
 * @author pai4j
 * @since 2025-10-14
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class UserVipInfo implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 用户ID
     */
    private Long userId;

    /**
     * VIP等级
     */
    private UserVipLevel vipLevel;

    /**
     * VIP过期时间
     */
    private LocalDateTime expireTime;

    /**
     * 是否已过期
     */
    private Boolean expired;

    /**
     * 当前可用的并发任务额度
     */
    private Integer availableConcurrentTasks;

    /**
     * 队列优先级
     */
    private Integer priority;

    /**
     * 是否使用VIP通道
     */
    private Boolean useVipChannel;

    /**
     * 创建普通用户VIP信息
     */
    public static UserVipInfo createNormal(Long userId) {
        UserVipLevel level = UserVipLevel.NORMAL;
        return UserVipInfo.builder()
                .userId(userId)
                .vipLevel(level)
                .expired(false)
                .availableConcurrentTasks(level.getMaxConcurrentTasks())
                .priority(level.getPriority())
                .useVipChannel(false)
                .build();
    }

    /**
     * 判断是否为有效VIP
     */
    public boolean isValidVip() {
        return vipLevel != null && 
               vipLevel.isVip() && 
               (expired == null || !expired) &&
               (expireTime == null || expireTime.isAfter(LocalDateTime.now()));
    }
}

